package com.utc.cards.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Scores
{
    private List<Map<String, Integer>> games = new ArrayList<Map<String, Integer>>();

    public List<Map<String, Integer>> getGames()
    {
        return games;
    }

    public void setGames(List<Map<String, Integer>> tours)
    {
        this.games = tours;
    }

    /**
     * 1ere partie = index 0
     */
    public Map<String, Integer> getScoresByGameIndex(int index)
    {
        if (index >= 0 && index < games.size())
        {
            return games.get(index);
        }
        else
        {
            return null;
        }
    }

    /**
     * 1ere partie = index 0
     */
    public void setScoresByGameIndex(int index, Map<String, Integer> gameScores)
    {
        if (index == games.size())
        {
            games.add(gameScores);
        }
        else if (index < games.size())
        {
            games.set(index, gameScores);
        }
        else
        {
            throw new RuntimeException("Saut de partie dans le tableau des scores");
        }
    }

    public Map<String, Integer> getLastPartyScore()
    {
        if (games.size() > 0)
        {
            return games.get(games.size() - 1);
        }

        return null;
    }
}
